package com.company.service.impl;

import com.company.entity.User;
import com.company.service.RegisterService;

import java.util.Scanner;
//注册
public class RegisterServiceImpl implements RegisterService {
    @Override
    public void execute() {
        Scanner input = new Scanner(System.in);
        while (true) {
            System.out.print("请输入注册登录名: ");
            String name = input.next();
            System.out.print("请输入注册手机号: ");
            int phone = input.nextInt();
            System.out.print("请输入注册密码: ");
            String pwd = input.next();
            System.out.print("请再次输入注册密码: ");
            String pwd2 = input.next();
            if (!pwd.equals(pwd2)) {
                System.out.println("两次密码不一致,请重新输入！");
                continue;
            } else {
                User user = new User(name, pwd);
                SysUserServiceImpl sysUserService = new SysUserServiceImpl();
                if (sysUserService.register(user, phone) == 1) {
                    System.out.println("创建成功!");
                    break;
                } else {
                    System.out.println("创建失败!");
                }
            }
        }
    }
}
